package com.xinqi.xinqidev.controller;

import com.xinqi.xinqidev.pojo.entity.QuestionAnswerLog;
import com.xinqi.xinqidev.pojo.result.Result;
import com.xinqi.xinqidev.pojo.result.ResultUtil;
import com.xinqi.xinqidev.service.QuestionAnswerLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xin麒
 * @date 2023/12/25 14:51
 */
@RestController
@Slf4j
@RequestMapping("/Question-Answer-Log")
public class QuestionAnswerLogController {

    @Autowired
    private QuestionAnswerLogService questionAnswerLogService;

    @GetMapping("/testGet")
    public List<QuestionAnswerLog> testGet(){
        List<QuestionAnswerLog> result = questionAnswerLogService.testGet();
        log.debug("result is "+ result);
        return result;
    }


    @GetMapping("/testGet2")
    public List<QuestionAnswerLog> testGet2(){
        List<QuestionAnswerLog> result = questionAnswerLogService.testGet2();

        log.debug("result is " + result);
        return result;
    }


    @PostMapping("/testInsert")
    public Result testInsert(@RequestBody QuestionAnswerLog questionAnswerLog){
        return questionAnswerLogService.testInsert(questionAnswerLog);
    }

    /**
     * {"userId":1231223,"question":"xawxwsss2a","answer":"hahhahahha","isExistException":false,"sid":null}
     */

    @PostMapping("/testSave")
    public Result testSave(@RequestBody QuestionAnswerLog questionAnswerLog){
        log.debug("questionAnswerLog is "+ questionAnswerLog);
        //QuestionAnswerLog(id=null, userId=1231223, question=xawxwsss2a, answer=hahhahahha, createTime=null, isExistException=false, sId=null)
        return ResultUtil.ok(questionAnswerLogService.save(questionAnswerLog));
    }





}
